package com.qc31.monitorlib.ui.adapter

import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.qc31.baselib.utils.loadStringDImgError
import com.qc31.baselib.utils.loadVideoImg
import com.qc31.comlib.entity.AlarmMedia
import com.qc31.monitorlib.R

/**
 *@Author Jasper
 *@Time   2020/12/2
 *@Desc   照片
 */
class MediaAdapter(private val isVideo: Boolean = true) :
    BaseQuickAdapter<AlarmMedia.MediaInfo, BaseViewHolder>(
        R.layout.item_media_photo
    ) {
    var index = 0
    override fun convert(
        holder: BaseViewHolder,
        item: AlarmMedia.MediaInfo
    ) {
        item.run {
            if (isVideo)
                holder.getView<ImageView>(R.id.ivVideoPhoto).loadVideoImg(context, fullLink, 1000)
            else
                holder.getView<ImageView>(R.id.ivVideoPhoto).loadStringDImgError(context, fullLink)

            holder.setVisible(R.id.ivVideoState, isVideo)
            if (isVideo)
                holder.setVisible(R.id.ivVideoState, holder.layoutPosition != index)
        }
    }
}